#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

bool is_ok(int s, int i)
{
	string ss;
	while (s)
	{
		ss.push_back(s % i);
		s /= i;
	}
	string ss1 = ss;
	reverse(ss1.begin(), ss1.end());
	return ss == ss1;
}
bool check(int s)
{
	int cnt = 0;
	for (int i = 2; i <= 10; i++)
		if (is_ok(s, i)) cnt++;
	if (cnt >= 2) return true;
	return false;
}
int main()
{
	int n = 0, s = 0;
	cin >> n >> s;
	while (n)
	{
		if (check(++s)) { cout << s << endl; n--; }
	}
	return 0;
}